#include<iostream>
#include<sys/wait.h>
#include<sys/types.h>
#include<cstdlib>
#include<cstdio>
#include<unistd.h>
#include<cstring>
#define NUM 10
using namespace std;

typedef void(*func_t)();
func_t taskrunlist[NUM];
void task1(){
  cout<<"task running!"<<endl;
}
void task2(){
  cout<<"task running!"<<endl;
}

void task3(){
  cout<<"task running!"<<endl;
}
void task4(){
  cout<<"task running!"<<endl;
}
void loadtask(){
  memset(taskrunlist,0,sizeof(taskrunlist));
  taskrunlist[0]= task1;
  taskrunlist[1]= task2;
  taskrunlist[2]= task3;
  taskrunlist[3]= task4;
}



int main(){
  pid_t pid = fork();
  if(pid == 0){
    int time = 10;
    while(time--){
      cout<<"child is running"<<time<<endl;
      sleep(3);
    }
    exit(0);
  }
  while(1){

    loadtask();
    int status =0;
    int ret = waitpid(pid,&status,WNOHANG);
    if(ret == 0){
      for(int i = 0 ; taskrunlist[i];i++){
        taskrunlist[i]();
        sleep(1);
      }
    }else if (ret > 0){
      cout<<"call success:exit code :"<<((status>>8)&0xff)<<"exit sig :"<<(status&0x7f)<<endl;
      break;
    }
  }
  return 0;
}
